package org.budo.tencent.response;

import org.budo.support.http.client.Response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * @author lmw
 */
public class MeResponse extends AbstractResponse {
    private static final long serialVersionUID = -7106857281535413804L;

    private String openId;

    public MeResponse() {}

    public MeResponse(Response response) {
        this.setResponse(response);

        String responseBody = response.getBody();
        String json = responseBody.replace("callback(", "").replace(");", "");
        JSONObject jsonObject = JSON.parseObject(json);

        this.setOpenId(jsonObject.getString("openid"));
    }

    public String getOpenId() {
        return this.openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    @Override
    public String toString() {
        return super.toString() + ", openid=" + this.getOpenId();
    }
}